package com.example.security6atguigu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.security6atguigu.config.DBUserDetailsManager;
import com.example.security6atguigu.entity.User;
import com.example.security6atguigu.service.UserService;
import com.example.security6atguigu.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
* @author L
* @description 针对表【user】的数据库操作Service实现
* @createDate 2024-05-22 23:02:11
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Resource
    private DBUserDetailsManager userDetailsManager;
    @Override
    public void saveUserDetails(User user) {
        UserDetails userDetails = org.springframework.security.core.userdetails.User
                .withDefaultPasswordEncoder()
                .username(user.getUsername())
                .password(user.getPassword())
//                .roles("USER")
                .build();
        userDetailsManager.createUser(userDetails);
    }

}




